package program_storage;


/**
 * Enumeration for the different token types.
 *
 */
public enum TokenType {
	// Special Tokens
	ERR, EOF("\uffff"),

	// Separators
	SEMI(";", true),
	COLON(":", true),

	// Literals
	INT_LITERAL,
	DOUBLE_LITERAL,

	// Machine operators
	MUL("MUL", true),
	DIV("DIV", true),
	GDIV("GDIV", true),
	ADD("ADD", true),
	SUB("SUB", true),
	SHIFTL("SHIFTL", true),
	SHIFTR("SHIFTR", true),
	LESS("LESS", true),
	LESSEQUAL("LESSEQUAL", true),
	GREATER("GREATER", true),
	GREATEREQUAL("GREATEREQUAL", true),
	EQUAL("EQUAL", true),
	NOTEQUAL("NOTEQUAL", true),
	AND("AND", true),
	OR("OR", true), 
	WRITEINT("WRITEINT", true),
	WRITECHAR("WRITECHAR", true),
	WRITEDOUBLE("WRITEDOUBLE", true),
	WRITEBOOL("WRITEBOOL", true),
	READINT("READINT", true),
	READDOUBLE("READDOUBLE", true),
	READCHAR("READCHAR", true),
	SEL("SEL", true),
	XOR("XOR", true),
	MOD("MOD", true),
	JZ("JZ", true),
	JUMP("JUMP", true),
	DUP("DUP", true),
	HALT("HALT", true),
	CALLMETH("CALLMETH", true),
	GETVALUE("GETVALUE", true),
	SETVALUE("SETVALUE", true),
	LOAD("LOAD", true),
	STORE("STORE", true),
	LDIC("LDIC", true),
	LDDC("LDDC", true),
	MAIN("Main", true),
	METHOD("Method", true),
	NEW("NEW", true),
	RETURN("RETURN", true),
	RETURNVALUE("RETURNVALUE", true),
	INTTOBOOL("INTTOBOOL", true),
	LENGTH("LENGTH", true);
	
	/**
	 * The text (character representation of this token).
	 */
	private final String text;

	/**
	 * true, if this token types text is a keyword.
	 */
	private final boolean isKeyword;

	/**
	 * Creates a new token type for the given parameters.
	 *
	 * @param text       The text (character representation of this token)
	 * @param isKeyword  true, if this token types text is a keyword
	 */
	private TokenType(String text, boolean isKeyword) {
		this.text = text;
		this.isKeyword = isKeyword;
	}

	/**
	 * Creates a new token type that is no keyword for the given parameters.
	 *
	 * @param text  The text (character representation of this token)
	 */
	private TokenType(String text) {
		this(text, false);
	}

	/**
	 * Creates a new TokenType
	 */
	private TokenType() {
		this("");
	}

	/**
	 * Returns the text (character representation) of this token type.
	 *
	 * @return the text of this token type
	 */
	public String getText() {
		return text;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see java.lang.Enum#toString()
	 */
	public String toString() {
		return text.length() > 0 ? text : name();
	}

	/**
	 * Returns true, if this token types text is a keyword.
	 *
	 * @return true, if this tokens types text is a keyword
	 */
	public boolean isKeyword() {
		return isKeyword;
	}

}
